FROM php

MAINTAINER Amumu <amumu-t@qq.com>

RUN apt-get update -y && apt-get install -y \
    g++ \
    git \
    vim \
    curl \
    apt-utils \
    zlib1g-dev \
    libicu-dev \
    libmemcached-dev \
    unzip \
    libzip-dev \
    libfreetype6 \
    libfreetype6-dev \
    libxml2-dev \
    doxygen \
    cmake \
    python \
    jpegoptim \
    optipng \
    pngquant \
    gifsicle \
    libmagickwand-dev \
    imagemagick

RUN pecl channel-update pecl.php.net \
    && docker-php-ext-configure intl \
    && docker-php-ext-install intl

# pecl: igbinary msgpack memcached redis zip mongodb amqp yaml
RUN pecl install igbinary
RUN pecl install msgpack
RUN pecl install memcached-3.1.3
RUN pecl install redis
#RUN pecl install zip-1.15.4
RUN pecl install mongodb
#RUN pecl install grpc
#RUN pecl install protobuf
#RUN pecl install amqp
# Please install libyaml
#RUN pecl install yaml
RUN docker-php-ext-enable igbinary msgpack memcached redis mongodb

# memcached igbinary
#RUN docker-php-ext-enable memcached-igbinary

# pdo mysql iconv mbstring json bcmath Exif Tokenizer gmp imap
RUN docker-php-ext-install mysqli
RUN docker-php-ext-install pdo_mysql
RUN docker-php-ext-install iconv
#RUN docker-php-ext-install mbstring
RUN docker-php-ext-install json
RUN docker-php-ext-install bcmath
RUN docker-php-ext-install exif
RUN docker-php-ext-install tokenizer
RUN docker-php-ext-enable mysqli pdo_mysql iconv json tokenizer

# calendar sockets gettext dom xml
RUN docker-php-ext-configure calendar && docker-php-ext-install calendar && docker-php-ext-enable calendar
RUN docker-php-ext-configure sockets && docker-php-ext-install sockets && docker-php-ext-enable sockets
RUN docker-php-ext-configure gettext && docker-php-ext-install gettext && docker-php-ext-enable gettext
RUN docker-php-ext-configure dom && docker-php-ext-install dom && docker-php-ext-enable dom
RUN docker-php-ext-configure xml && docker-php-ext-install xml && docker-php-ext-enable xml
#RUN docker-php-ext-configure imagemagick && docker-php-ext-install imagemagick && docker-php-ext-enable imagemagick

# opencc
ADD opencc /usr/local/opencc
RUN cd  /usr/local/opencc && make && make install
ADD opencc4php /usr/local/opencc4php
RUN cd /usr/local/opencc4php && phpize && \
    ./configure --with-opencc=/usr/local/opencc --with-php-config=/usr/local/bin/php-config && \
    make && make install && \
    docker-php-ext-enable opencc

# swoole
RUN cd /root && pecl download swoole && \
    tar -zxvf swoole* && cd swoole* && \
    phpize && ./configure && \
    make && make install && docker-php-ext-enable swoole

# gd
ADD libpng-1.6.37 /usr/local/libpng
RUN cd /usr/local/libpng && \
    ./configure --prefix=/usr/local/libpng && \
    make && \
    make install

ADD jpeg-9c /usr/local/jpeg
RUN cd /usr/local/jpeg && ./configure --prefix=/usr/local/jpeg && make && make install && \
    mkdir -p /usr/local/jpeg/include && \
    mkdir -p /usr/local/jpeg/lib && \
    mkdir -p /usr/local/jpeg/bin && \
    mkdir -p /usr/local/jpeg/man/man1
RUN docker-php-ext-configure gd \
    --with-php-config=/usr/local/bin/php-config \
    --with-freetype-dir=/usr/local/freetype \
    --with-png-dir=/usr/local/libpng \
    --with-jpeg-dir=/usr/local/jpeg \
    && docker-php-ext-install gd && docker-php-ext-enable gd


# composer
RUN php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');" && \
    php composer-setup.php && \
    php -r "unlink('composer-setup.php');" && \
    mv composer.phar /usr/local/bin/composer && composer selfupdate &&  composer

# phpcpp
#ADD phpcpp /phpcpp
#RUN cd /phpcpp && make && make install

#protoc
#ADD protobuf-3.8.0 /tmp/protobuf
#RUN cd /tmp/protobuf && \
#    ./configure --prefix=/usr/local/protobuf && \
#    make && \
#    make install && \
#    cp /usr/local/protobuf/bin/protoc /usr/local/bin/protoc && \
#    protoc --version && \
#    rm -rf /tmp/protobuf

ADD php.ini /usr/local/etc/php/php.ini

# 添加容器启动后的执行脚本
ADD start_swoole.sh /start_swoole.sh
RUN chmod 777 /start_swoole.sh
# 扩展
RUN php -m
RUN php -v

# 项目目录
WORKDIR /var/www

CMD ["php-fpm"]

EXPOSE 9000